package org.aileen.springmvc.Controller;

import org.aileen.springmvc.model.MessageInfo;
import org.aileen.springmvc.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//接口的实现
@RequestMapping("/message")
@RestController
public class MessageController {

    //注入service
    @Autowired
    private MessageInfoService messageInfoService;

//    //存储留言信息
//    private List<MessageInfo>  messageInfoList = new ArrayList<>();

    @RequestMapping(value = "/publish" , method = RequestMethod.POST)
    public Boolean publish(@RequestBody MessageInfo messageInfo) {
        //打印日志:
        System.out.println("发表留言");
        //**********添加到数据库中
//        messageInfoList.add(messageInfo);
        messageInfoService.insertMessage(messageInfo);
        return true;
    }

    //留言板列表
    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        //**********从数据库中查询留言信息
        return
        messageInfoService.queryMessage();
//        return messageInfoList;
    }
}
